**** N= 276 referred patients

sum edad if referred==1, detail
sum births if incluido==1 & referred==1 & births>0, detail
sum births if incluido==1 & referred==1 & births==0, detail
tab priorpregnancyreferral_n if referred==1

**** N= 506 non referred patients 

sum edad if referred==0, detail
sum births if incluido==1 & referred==0 & births>0, detail
sum births if incluido==1 & referred==0 & births==0, detail
tab priorpregnancyreferral_n if referred==0

*** Outcomes
g resolucionparto=Methodofdelivery if Methodofdelivery_obsDatetime<(td(1/04/2018))
replace resolucionparto=Methodofdelivery_1 if Methodofdelivery_obsDatetime_<Methodofdelivery_obsDatetime
label var resolucionparto tipopartoporfecha

tab resolucionparto if referred==1
tab resolucionparto if referred==0
g uterine_rupture=0
replace uterine_rupture=1 if open=="1728-5"

**** Statistical analysis
ttest edad, by(referred)
ttest births, by(referred)
g nulliparous=(births==0)
tab nulliparous
prtest nulliparous, by(referred)
tab priorpregnancyreferral_n referred, chi

**** Delivery outcomes
g home_delivery=(resolucionparto=="Parto normal en la casa")
g cesarean_delivery=(resolucionparto=="cesarea programada" | resolucionparto=="cesarea urgente")
g facility_delivery=(resolucionparto=="Parto normal en el hospital o CUM" | resolucionparto=="Parto urgente en el hospital o CUM")

*** stats delivery outcomes
tab home_delivery referred, chi
tab cesarean_delivery referred, chi
tab facility_delivery referred, chi

tab neo_death referred, chi
tab hypertensivedisorderpregn referred, col chi
tab stillbirth referred,col chi
tab uterine_rupture referred,col chi

**** General demographic description of Cohort N=467 ****
sum edad if incluido, detail
/// Partos o cesareas en el hospital
tab resolucionparto if births>0 & incluido==1 



**** Emergency referral during pregnancy concept 163188
** Pienso que esta variable no se puede utilizar porque las respuestas estan sesgadas
tab prior_referral_posnatal referred, chi
tab prior_referral_posnatal referred, col



